<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>操作日志</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">操作日期</label>
                    <div class="layui-input-block">
                        <input type="text" name="operate_time" placeholder="请输入" autocomplete="off" class="layui-input" id="operate_time">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-user-table" lay-filter="LAY-user-table"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="isDel"><i class="layui-icon">&#xe640;</i> 删除</button>
                </div>
            </script>
        </div>
    </div>
</div>

<script src="/static/layui/layui.js"></script>
<script src="/static/common/js/layTool.js"></script>
<script>
    layui.config({
        base: '/static/admin/'
    }).use(['table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;

        var active = {

        };

        $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        // 监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;

            // 执行重载
            table.reload('LAY-user-table', {
                where: field
            });
        });

    });

    renderTable();
    // 渲染表格
    function renderTable() {
        layui.use(['table', 'form','layer'], function () {
            var $ = layui.$
                ,form = layui.form
                ,layer = layui.layer
                ,table = layui.table;

            table.render({
                elem: "#LAY-user-table",
                url: "/admin/log/operate",
                cols: [
                    [{type:'checkbox'}, {
                        field: "log_id",
                        title: "日志ID"
                    }, {
                        field: "operator",
                        title: "操作者",
                    }, {
                        field: "operator_ip",
                        title: "操作者IP"
                    }, {
                        field: "operate_method",
                        title: "操作方法"
                    }, {
                        field: "operate_desc",
                        title: "操作描述"
                    }, {
                        field: "operate_time",
                        title: "操作时间"
                    }]
                ],
                page: !0,
                limit: 20,
                toolbar: '#toolbarDemo',
                height: "full-220",
                text: "对不起，加载出现异常！"
            });

            //头工具栏事件
            table.on('toolbar(LAY-user-table)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data;
                var deList=[];
                data.forEach(function(n,i){
                    deList.push(n.log_id);
                });
                if(obj.event == 'isDel') {
                    if(deList.length) {
                        layer.ready(function () {
                            var index = layer.confirm('您确定要删除该日志？', {
                                title: '友情提示',
                                icon: 3,
                                btn: ['确定', '取消']
                            }, function () {

                                $.getJSON('{:url("log/isDelOperate")}', {
                                    id: deList
                                }, function (res) {

                                    if (0 == res.code) {

                                        layer.msg(res.msg);
                                        setTimeout(function () {
                                            renderTable();
                                        }, 300);
                                    } else {
                                        layer.alert(res.msg);
                                    }
                                });
                            }, function () {

                            });
                        });
                    } else {
                        layer.tips('请选择需要删除的行',$('#LAY-user-table'),{
                            tips:[3,'#5fb878']
                        })
                    }
                }

            });

        });
    }

    layTool.layDate('#operate_time')
</script>
</body>
</html>
